package cn.ekuma.odbo.mobile.helper

import android.widget.ArrayAdapter
import cn.ekuma.odbo.mobile.base.I_BrowsableEditableData
import cn.ekuma.odbo.mobile.room.BaseDao

class ArrayAdapterBrowsEditableHelper<T>(val adpater: ArrayAdapter<T>, val baseDao: BaseDao<T>): AbstractBrowableHelper<T>() ,I_BrowsableEditableData<T>{
    override fun moveTo(i: Int) {
        if(currentIntIndex==i||!moveToAble(i))
            return
        currentIntIndex=i
        if(_itemCount>=0&&currentIntIndex<_itemCount-1) {
            currentItem = adpater.getItem(currentIntIndex)

        }
    }

    override fun getItemCount(): Int {
        return adpater.count
    }

    override fun insertItem(item: T) {
        baseDao.insert(item)
    }

    override fun updateItem(item: T) {
        baseDao.update(item)
    }

    override fun deleteItem(item: T) {
        baseDao.delete(item)
    }
}